
<div id="newNavApp">
    <nav class="navbar navbar-expand-lg navbar-dark bg-dark">
        <a class="navbar-brand" href="#">Music</a>
        <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
            <span class="navbar-toggler-icon"></span>
        </button>

        <div class="collapse navbar-collapse" id="navbarSupportedContent">
            <ul class="navbar-nav mr-auto">
                <li class="nav-item">
                    <a class="nav-link" href="/music_platform/pages/index.html">发现音乐<span class="sr-only">(current)</span></a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="/music_platform/pages/myMusic.html">我的音乐</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="/music_platform/pages/follow.html">关注</a>
                </li>
            </ul>
            <form class="form-inline my-2 my-lg-0 mr-5">
                <input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search">
                <button class="btn btn-outline-success my-2 my-sm-0" type="submit">搜索</button>
            </form>
            <a v-if="user.username===''" class="btn-sm btn-primary" href="/music_platform/pages/login.html">登录</a></span>
            <a v-if="user.username!==''" class="text-primary">{{user.username}}</a>
            <a v-if="user.username!==''" class="btn-sm btn-primary btn-sm" href="/music_platform/user/logout">退出</a>
        </div>
    </nav>
</div>
<script src="js/vue.js"></script>
<script src="js/axios.js"></script>
<script>
    let newNavApp = new Vue({
        el:"#newNavApp",
        data:{
            user:{
                uid:'',
                username:'',
            },
        },
        methods:{
            getUser:function (){
                let _this = this;
                axios.get("/music_platform/user/session").then(function (response){
                    if (response.data.flag===true){
                        _this.user=response.data.data;
                    }
                })
            },
        },
        created:function (){
            this.getUser();
        }
    })
</script>